package com.jiabowen.store.service.impl;

import com.jiabowen.store.entity.Address;
import com.jiabowen.store.entity.Product;
import com.jiabowen.store.mapper.AddressMapper;
import com.jiabowen.store.mapper.ProductMapper;
import com.jiabowen.store.service.IAddressService;
import com.jiabowen.store.service.IDistrictService;
import com.jiabowen.store.service.IProductService;
import com.jiabowen.store.service.exception.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ProductServiceImpl implements IProductService {

    @Autowired
    private ProductMapper productMapper;

    /**
     * 热销商品 四个
     * @return
     */
    @Override
    public List<Product> findHotList() {
        List<Product> list = productMapper.findHotList();
        for (Product product : list) {
            product.setPriority(null);
            product.setCreatedUser(null);
            product.setCreatedTime(null);
            product.setModifiedUser(null);
            product.setModifiedTime(null);
        }
        return list;
    }

    @Override
    public Product findProductById(Integer id) {
        //根据id调用私有方法执行查询，获取商品数据
        Product result = productMapper.findById(id);
        if (result == null){
            throw new ProductNotFoundException("尝试访问的商品不存在");
        }
        //将查询结果中的部分属性设置为null
        result.setPriority(null);
        result.setCreatedUser(null);
        result.setCreatedTime(null);
        result.setModifiedUser(null);
        result.setModifiedTime(null);
        // 返回查询结果
        return result;
    }


}
